package com.guigu.tankai.controller;

import com.guigu.aop.OpLog;
import com.guigu.liuzhireng.pojo.PageVo;
import com.guigu.tankai.pojo.Dfile;
import com.guigu.tankai.service.DfileService;
import com.guigu.util.service.IDService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("Dflile.do")
public class DfileController {
    @Autowired
    DfileService d;
    @Autowired
    IDService idService;

    public static String getFirstkindName(String Firstkindid){
        String str ="";
        switch (Firstkindid){
            case "01":
                str +="电子";
                break;
            case "02":
                str +="家具";
                break;
            default:
                str = null;
                break;
        }
        return str;
    }
    public static String getSecondkindidName(String Secondkindid){
        String str ="";
        switch (Secondkindid){
            case "01":
                str +="计算机";
                break;
            default:
                str = null;
                break;
        }
        return str;
    }
    public static String getThirdkindidName(String Thirdkindid){
        String str ="";
        switch (Thirdkindid){
            case "01":
                str +="服务器";
                break;
            default:
                str = null;
                break;
        }
        return str;
    }
    //添加产品档案
    @RequestMapping("addflie")
    @OpLog(opModule = "产品档案管理",operType = "添加产品",operDesc = "此方法用于添加产品和物料")
    public String addflie(Dfile dfile){
        String productID = idService.ProductID(dfile.getFirstkindid(), dfile.getSecondkindid(), dfile.getThirdkindid());
        dfile.setProductid(productID);
        dfile.setFirstkindname(getFirstkindName(dfile.getFirstkindid()));
        dfile.setSecondkindname(getSecondkindidName(dfile.getSecondkindid()));
        dfile.setThirdkindname(getThirdkindidName(dfile.getThirdkindid()));
        d.insertSelective(dfile);
        return "/tan_kai/Addfile.html";
    }
    @RequestMapping("/chaname")
    @ResponseBody
    public int chaname(String name){
        return  d.selname(name);
    }

    //查询条件为S001-0: 等待审核的分页数据
    @RequestMapping("/pageDf")
    @ResponseBody
    public PageVo<Dfile> pageDf(@RequestBody PageVo<Dfile> f){
        return d.PageDf(f.getNum(),f.getSize(),f.getObj());
    }
    //修改产品档案的状态为S001-1: 审核通过
    @RequestMapping("upflie")
    @OpLog(opModule = "产品档案管理",operType = "修改产品",operDesc = "此方法用于修改产品状态为已审核")
    public String  upflie(Dfile dfile){
        d.updateByPrimaryKey(dfile);
        return  "/tan_kai/page.html";
    }
    //查询条件为S001-1: 审核通过的分页数据
    @RequestMapping("/pagecx")
    @ResponseBody
    public PageVo<Dfile> pageCX(@RequestBody PageVo<Dfile> f){
        return d.Pagecx(f.getNum(),f.getSize(),f.getObj());
    }
    //根据id修改全部
    @RequestMapping("upfliebg")
    @OpLog(opModule = "产品档案管理",operType = "修改产品",operDesc = "此方法用于修改产品所以数据")
    public String  upfliebg(Dfile dfile){
        d.updateBy(dfile);
        return  "/tan_kai/listbg.html";
    }
    //修改产品档案的状态为C001-0: 未删除
    @RequestMapping("upflieysc")
    @OpLog(opModule = "产品档案管理",operType = "修改产品",operDesc = "此方法用于修改产品为未删除")
    public String  upflieysc(Dfile dfile){
        d.DeleteTag1(dfile);
        return  "/tan_kai/Dfysc.html";
    }
    //修改产品档案的状态为S001-1: 审核通过 和 C001-1: 已删除
    @RequestMapping("updatedela")
    @OpLog(opModule = "产品档案管理",operType = "修改产品",operDesc = "此方法用于修改产品为已删除")
    public String  updatedel(Dfile dfile){
        d.DeleteTag(dfile);
        return  "/tan_kai/Dfdel.html";
    }
    //查询产品档案状态为S001-1: 审核通过 和 C001-0: 未删除
    @RequestMapping("/pagecxC")
    @ResponseBody
    public PageVo<Dfile> pagecxC(@RequestBody PageVo<Dfile> f){
        return d.pagecxC(f.getNum(),f.getSize());
    }
    //查询产品档案状态为 C001-1: 已删除
    @RequestMapping("/pageysc")
    @ResponseBody
    public PageVo<Dfile> pageysc(@RequestBody PageVo<Dfile> f){
        return d.pageysc(f.getNum(),f.getSize());
    }
    //查询产品档案状态为 S001-1: 审核通过 和 C001-0: 未删除 还有 Y001-2: 物料
    @RequestMapping("/pagewl")
    @ResponseBody
    public PageVo<Dfile> pagewl(@RequestBody PageVo<Dfile> f){
        return d.pagewl(f.getNum(),f.getSize());
    }
    //删除
    @RequestMapping("/delDfl")
    @OpLog(opModule = "产品档案管理",operType = "删除产品",operDesc = "此方法用于删除产品")
    public String delDfl(String productid){
        d.deleteByPrimaryKey(productid);
        return "/tan_kai/Dfysc.html";
    }
    //查询产品档案状态为 S001-1: 审核通过 和 C001-0: 未删除 还有 Y001-1: 商品
    @RequestMapping("/pagecsp")
    @ResponseBody
    public PageVo<Dfile> pagecsp(@RequestBody PageVo<Dfile> f){
        return d.Pagecsp(f.getNum(),f.getSize());
    }






    // wenzhiyi
    @RequestMapping("WZYpage")
    @ResponseBody
    public PageVo<Dfile> WZYpage(@RequestBody PageVo<Dfile> pageVo){
        return d.WZYPage(pageVo.getNum(),pageVo.getSize());
    }

    // limeng
    @RequestMapping("/PageInfo")
    @ResponseBody
    public PageVo<Dfile> pageInfo(@RequestBody PageVo<Dfile> pageVo){
        return d.Page(pageVo.getNum(),pageVo.getSize());
    }




}
